class MyPageProcess {
    constructor() {
    }
    DoFileUpload() {
        if (this.ValidateBpmn($("#hzUploadFile"))) {
            this.FileUpload('hzUploadFile', parent.basePath + '/workflow/process_def/upload.html');
        }
    }
    FileUpload(fileElementId, upload_url) {
        var $loading = $("#" + "loading_" + fileElementId);
        var $err = $("#" + "error_" + fileElementId);
        var $butUpload = $("#" + "upload_" + fileElementId);

        $loading.ajaxStart(function () {
            $(this).show();
        }).ajaxComplete(function () {
            $loading.hide();
        });
        $err.ajaxStart(function () {
            $(this).hide();
        });

        $.ajaxFileUpload({
            secureuri: false,
            fileElementId: fileElementId,
            type: "POST",
            url: upload_url,
            timeout: 30 * 1000,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: {},
            cache: false,
            beforeSend: function () {
            },
            success: function (data) {
                if (data.success === false) {
                    $err.html(data.errorMsg).show();
                } else {
                    $butUpload.attr("disabled", true);
                    $("#filename_hzUploadFile").text(""); // 清空刚才选择的文件
                    ShowSuccessMessagePanel("流程部署成功。");
                    $(".success-msg").css({left:'200px'});
                    parent._Instance.FetchForPage();
                }
            },
            complete: function (xml, status) {
                $loading.unbind('ajaxStart');
                $loading.unbind('ajaxComplete');
                $err.unbind('ajaxStart');
            },
            error: function () {
            }
        });
        return false;
    }
    // 校验文件格式
    ValidateBpmn(obj) {
        var tmpFileValue = obj.val();
        //校验图片格式
        if (/^.*?\.(bpmn)$/.test(tmpFileValue.toLowerCase())) {
            return true;
        } else {
            ShowErrorMessagePanel("只能上传流程文件。");
            $(".error-msg").css({left:'200px'});
            return false;
        }
    }
}

let _Instance = null;

////-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    _Instance = new MyPageProcess();
    $("#loading").hide();
}

// 画面大小或者位置移动
function onPageResize() {
}
